//
// Created by Administrator on 2024/6/17.
// 递归二分法 找到有序数组给定值的索引, 未找到返回-1
//

#include <iostream>
#include <vector>
using namespace std;

int count_times(vector<int> v, int x, int count, int n)
{
    if (x <= count)
    {
        int m = (x + count) / 2;
        if (n > v[m])
            return count_times(v, m + 1, count, n);
        else if(n < v[m])
            return count_times(v, x, m - 1, n);
        else
            return m;
    }
    else
        return -1;

}

int main()
{
    vector<int> v{2,5,7,9,10,23,52};
    cout << count_times(v, 0, v.size() - 1, 2);
    return 0;
}
